#! /bin/bash

#采集日期
if [ $# -eq 0 ]
then
    DATE=`date -d "-1 day" +%Y-%m-%d`
else
    DATE=$1
fi

YEARSTR=`date -d "${DATE}" +%Y`
MONTHSTR=`date -d "${DATE}" +%m`
DAYSTR=`date -d "${DATE}" +%d`



hive -S -e "
INSERT INTO itcast_dwd.customer_relationship_dwd PARTITION(payment_time_year, payment_time_month, payment_time_day)
SELECT
    id,
    customer_id,
    nvl(origin_type, -1) origin_type,
    if(origin_type='NETSERVICE' or origin_type='PRESIGNUP', '1', '0') origin_type_state,
    nvl(itcast_clazz_id, -1) itcast_clazz_id,
    nvl(creator, -1) creator
    payment_time
    substr(dwd.payment_time, 12, 2) as payment_time_hour,
    substr(payment_time, 1, 4) payment_time_year,
    substr(payment_time, 6, 2) payment_time_month,
    substr(payment_time, 9, 2) payment_time_day
from itcast_ods.customer_relationship
WHERE deleted = 0 AND customer_id IS NOT NULL AND payment_state='PAID'
and substr(payment_time, 1, 10) ='${DATE}';"